import time


def bubble_sort(numbers):
    changed = True
    while changed:
        changed = False
        for i in range(len(numbers) - 1):
            if numbers[i] > numbers[i + 1]:
                numbers[i], numbers[i + 1] = numbers[i + 1], numbers[i]
                changed = True


def read_list(f):
    file = open(f, 'r', encoding='utf-8')
    info = file.readlines()
    return info


sorted_list = read_list("m1_sorted.txt")
reversed_list = read_list("m2_reverse.txt")
shuffled_list = read_list("m3_shuffle.txt")

start = time.time()
bubble_sort(sorted_list)
print("m1_sorted", round((time.time() - start) * 1000), "milliseconds")

start = time.time()
bubble_sort(reversed_list)
print("m2_reverse", round((time.time() - start) * 1000), "milliseconds")

start = time.time()
bubble_sort(shuffled_list)
print("m3_shuffle", round((time.time() - start) * 1000), "milliseconds")
